package com.sinochem.sales.service.service.impl;

import com.sinochem.sales.common.api.vo.AttachmentFileVO;
import com.sinochem.sales.common.exception.BusinessException;
import com.sinochem.sales.service.service.IAttachmentFileService;
import org.apache.log4j.Logger;
import org.sagacity.sqltoy.dao.SqlToyLazyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xuan😴🐶🐱🐽🌺  <a href="zhangshixuanj@163.com">联系作者</a>
 * @version Revision:v1.0,Date: 2018/5/16 11:46
 * @project parent
 * @description 文件
 * @Modification Date: 2018/5/16 11:46  {填写修改说明}
 */
@Service
public class AttachmentFileServiceImpl implements IAttachmentFileService {

    private final static Logger logger = Logger.getLogger(AttachmentFileServiceImpl.class);

    @Autowired
    private SqlToyLazyDao sqlToyLazyDao;

    /**
     * 添加文件
     *
     * @param attachmentFileVO
     * @return
     */
    @Override
    public AttachmentFileVO addAttachmentFile(AttachmentFileVO attachmentFileVO) {
        try {
            this.sqlToyLazyDao.save(attachmentFileVO);
            return attachmentFileVO;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("新增文件操作失败!:{}", e);
            throw new BusinessException("新增文件操作失败!");
        }
    }

    /**
     * 加载文件
     *
     * @param attachmentFileVO
     * @return
     */
    @Override
    public AttachmentFileVO loadAttachmentFile(AttachmentFileVO attachmentFileVO) {
        try {
            return (AttachmentFileVO) this.sqlToyLazyDao.load(attachmentFileVO);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("加载文件失败!:{}", e);
            throw new BusinessException("加载文件失败!");
        }
    }
/*
    *//**
     * 批量查询附件
     *
     * @param attachmentFileVO 附件VO
     * @return
     *//*
    @SuppressWarnings("unchecked")
    @Override
    public List<AttachmentFileVO> findListAttachmentFileVO(AttachmentFileVO attachmentFileVO) {
        try {
            return sqlToyLazyDao.findBySql("sqltoy-find-list",
                    new String[]{"fileIdIds"},
                    new Object[]{attachmentFileVO.getFileIdIds()}, AttachmentFileVO.class);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("批量查询附件操作失败!:{}", e);
            throw new BusinessException("批量查询附件失败!");
        }
    }*/

}
